package org.aurora.framework.boot.common.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Objects;

/**
 * AbstractAnnotationMethodInterceptor
 * <pre>
 * description: 注解标记拦截器
 * create date: 2025-03-22 23:29:28
 * </pre>
 *
 * @author cao.yong
 */
public abstract class AbstractAnnotationMethodInterceptor<A extends Annotation> extends ApplicationObjectSupport implements MethodInterceptor {

    /**
     * 获取注解参数
     * @param method 被注解的方法
     * @param target 方法所属的对象实例
     * @param annotationType 注解类型
     * @return 注解实例
     */
    protected A getAnnotation(Method method, Object target, Class<A> annotationType) {
        A annotation = AnnotationUtils.findAnnotation(method, annotationType);
        if (Objects.isNull(annotation)) {
            annotation = AnnotationUtils.findAnnotation(target.getClass(), annotationType);
        }
        return annotation;
    }
}
